package com.aaa.service.impl;

import com.aaa.dao.UserDao;
import com.aaa.entity.User;
import com.aaa.service.TUserService;
import com.aaa.util.Result;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 荆豪峰
 * @version 1.0
 */
@Service
public class TUserServiceImpl implements TUserService {
    @Autowired
    private UserDao userDao;
    @Override
    public Result delete(Integer id) {
        int i = userDao.deleteById(id);
        return new Result(200,"删除成功",i);
    }

    @Override
    public Result add(User user) {
        int insert = userDao.insert(user);
        return new Result(200,"添加成功",insert);
    }

    @Override
    public Result update(User user) {
        UpdateWrapper<User> wrapper = new UpdateWrapper<>();
        wrapper.eq("id",user.getId());
        int update = userDao.update(user, wrapper);
        return new Result(200,"修改成功",update);
    }

    @Override
    public Result SelectAll(Integer currentPage, Integer pageSize) {
        //给分页插件设置格式
        Page<User> page=new Page<>(currentPage,pageSize);

        //处理数据，需要两个参数，第一个是分页格式 第二个还是设置查询结果的筛选条件
        Page<User> pageAfter=userDao.selectPage(page,null);

        return new Result(200,"查询用户",pageAfter);
    }
}
